define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dbusercare/dbusercare/index',
                    add_url: 'dbusercare/dbusercare/add',
                    edit_url: 'dbusercare/dbusercare/edit',
                    del_url: 'dbusercare/dbusercare/del',
                    multi_url: 'dbusercare/dbusercare/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        //ID
                        {field: 'id', title: __('Id'), sortable: true},
                        //账号
                        {field: 'account', title: __('Account')},
                        // 姓名
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        //性别
                        {
                            field: 'sex',
                            title: __('Sex'),
                            formatter: function (value, row, index) {
                                return value == 0 ? __('Secrecy') : value == 1 ? __('Male') : __('Female');
                            },
                            searchList: {0: __('Secrecy'), 1: __('Male'), 2: __('Female')} //searchList 搜索中的列表
                        },
                        //生日
                        {field: 'birthday', title: __('Birthday'), visible: false, operate: false},
                        // 电话号码
                        {field: 'tel', title: __('Tel')},
                        //医院
                        {field: 'hospital', title: __('Hospital')},
                        //创建类型
                        {
                            field: 'create_type',
                            title: __('CreateType'),
                            formatter: function (value, row, index) {
                                return value == 1 ? __('UserRegister') : __('UserRegister');
                            },
                            searchList: {1: __('UserRegister'), 2: __('AddBackground')}
                        },
                        //认证状态
                        {
                            field: 'attestation',
                            title: __('Attestation'),
                            // formatter: Table.api.formatter.status,
                            // custom: {0: 'danger', 1: 'success'},
                            // searchList: {0: __('Unverified'), 1: __('Verified')},
                            formatter: Table.api.formatter.toggle,
                            searchList: {"0": __('Unverified'), "1": __('Verified')},
                        },
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        // {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        // {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        // {field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
                        // {field: 'score', title: __('Score'), operate: 'BETWEEN', sortable: true},
                        //连续登录天数
                        {
                            field: 'successions',
                            title: __('Successions'),
                            visible: false,
                            operate: 'BETWEEN',
                            sortable: true
                        },
                        //最长登录天数
                        {
                            field: 'maxsuccessions',
                            title: __('Maxsuccessions'),
                            visible: false,
                            operate: 'BETWEEN',
                            sortable: true
                        },
                        //登录ip
                        {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search,searchable:false},
                        // {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
                        {
                            field: 'state',
                            title: __('State'),
                            // formatter: Table.api.formatter.status,
                            // custom: {0: 'danger', 1: 'success'},
                            // searchList: {0: __('Disable'), 1: __('Enable')}
                            formatter: Table.api.formatter.toggle,
                            searchList: {"0": __('Disable'), "1": __('Enable')},
                        },
                        {
                            field: 'logintime',
                            title: __('Logintime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {
                            field: 'create_time',
                            title: __('CreateTime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
            add: function () {
                Controller.api.bindevent();
            }
        ,
            edit: function () {
                Controller.api.bindevent();
            }
        ,
            api: {
                bindevent: function () {
                    Form.api.bindevent($("form[role=form]"));
                }

            }
        };
        $.validator.config({
        rules: {
            pwd: function (element) {
                //如果直接返回文本，则表示失败的提示文字
                if (!element.value.toString().match(/^[A-Za-z0-9]{6,20}$/)) {
                    return __("The password is a combination of 6-20 letters or numbers");
                }
            },
            account:function (element){
                if (!element.value.toString().match(/^[A-Za-z0-9]{4,20}$/)) {
                    return __("The account is a combination of 4-20 letters or numbers");
                }
            }

        }
    });
        return Controller;
    }
)
